const { Sequelize } = require("sequelize");

const sequelize = new Sequelize({
	host: "localhost",
	port: "3306",
	username: "root",
	password: "Qian1234056.",
	database: "novel",
	dialect: "mysql",
	define: {
		charset: "utf8mb4",
	},
	dialectOptions: {
		collate: "utf8mb4_unicode_ci",
	},
});

// 测试连接
sequelize
	.authenticate()
	.then(_ => {
		console.log("数据库连接成功!");
	})
	.catch(err => {
		console.log("数据库连接失败! ", err);
	});

sequelize.sync();

module.exports = sequelize;
